let loginModule = (function () {
  const handleLogin = () => {
    let $userName = $(".userName"),
      $userPass = $(".userPass"),
      $btn = $(".submit");

    $btn.click(async () => {
      let account = $userName.val().trim(),
        password = $userPass.val().trim();

      // 校验格式（非空）
      if (account === "" || password === "") {
        alert("账号/密码不能为空o(╥﹏╥)o");
        return;
      }

      // 密码MD5加密
      password = md5(password);

      // 发送POST请求 把数据发送给服务器做校验
      let result = await axios.post("/user/login", {
        account, password
      })

      // 二次判断是否请求到成功状态的数据
      if (Number(result.code) === 0) {
        alert("登录成功，点击确定跳转到首页(#^.^#)");
        window.location.href = "index.html";
      } else {
        alert("账号/密码错误o(╥﹏╥)o");
      }
    })
  }
  return {
    init() {
      handleLogin();
    }
  }
})();

loginModule.init();